/* 
 * Copyright (C) 2012 Martin Řehánek <Martin.Rehanek at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

goog.provide('kramerius.audio.ui.ProgressInfo');

goog.require('kramerius.audio.ui.PlayerComponent');
goog.require('kramerius.audio.utils');
goog.require('goog.dom');


/**
 * @constructor 
 * @param {Element} container Element containing this component.
 * @param {kramerius.audio.Controller} controller Controller of the audio player.
 */
kramerius.audio.ui.ProgressInfo = function(container, controller){
    kramerius.audio.ui.PlayerComponent.call(this, container, controller);
    this.controller_.setProgressInfo(this);
    this.clear();
};
goog.inherits(kramerius.audio.ui.ProgressInfo, kramerius.audio.ui.PlayerComponent);


kramerius.audio.ui.ProgressInfo.prototype.clear = function(){
    this.totalLength_ = 0;
    this.position_ = 0;
    this.render_();
};


/**
 * Updates and renders position in track.
 * @param {number} position Position in active track in seconds.
 */
kramerius.audio.ui.ProgressInfo.prototype.setPosition = function(position){
    //    console.log("this.position_: " + this.position_);
    //    console.log("position: " + position);
    if (kramerius.audio.utils.differsByAtLeast(this.position_, position, 1)){
        this.position_ = position;
        this.render_();
        //console.log("ProgressInfo: updating position");
    }
};


/**
 * Updates and renders length of track.
 * @param {number} totalLength Total length of track in seconds.
 */
kramerius.audio.ui.ProgressInfo.prototype.setTotalLength = function(totalLength){
    this.totalLength_ = totalLength;
    this.render_();
};


kramerius.audio.ui.ProgressInfo.prototype.render_ = function(){
    var text = kramerius.audio.utils.secondsToTime(this.position_)
    + " / " + kramerius.audio.utils.secondsToTime(this.totalLength_);
    //this.setContent_("TODO" +text);
    this.setContent_(text);
};


/** @private **/
kramerius.audio.ui.ProgressInfo.prototype.setContent_ = function(content){
    goog.dom.setTextContent(this.container_, content);
};







